package hik;

import java.util.HashMap;
import java.util.Map;

import com.sun.jna.Pointer;

/**
 * 红外长连接 手动测温
 * 
 * @author fankai 2020-3-19 21:48:20
 *
 */
public class ManualCallback implements HCNetSDK.FRemoteConfigCallback {
	
	
	
	public ManualCallback() {
	}

	/**
	 * 回调函数
	 * 
	 * @date 2020/2/20 22:23
	 * @author fankai
	 * @param dwType, pBuffer, dwBufLen, dwUser]
	 **/
	@Override
	public void invoke(int dwType, Pointer pBuffer, int dwBufLen, Pointer dwUser) {
//		logger.info(device.getCode()+"--------------"+dwType+"------------------");
		switch (dwType) {
		case HCNetSDK.NET_SDK_CALLBACK_TYPE_STATUS:// 回调状态值
			int int1 = pBuffer.getInt(0);
			switch (int1) {
			case HCNetSDK.NET_SDK_CALLBACK_STATUS_SUCCESS: // 成功;
				break;
			case HCNetSDK.NET_SDK_CALLBACK_STATUS_PROCESSING: // 处理中
				break;
			case HCNetSDK.NET_SDK_CALLBACK_STATUS_FAILED: // 失败
				break;
			default:
				break;
			}
			break;
		case HCNetSDK.NET_SDK_CALLBACK_TYPE_PROGRESS: // 回调进度值
			break;
		case HCNetSDK.NET_SDK_CALLBACK_TYPE_DATA: // 回调数据内容
			String ruleName = "";

			float fMaxTemp = 0;
			float fMinTemp = 0;
			float fAvgTemp = 0;
			
			Map<String,Object> map = new HashMap<>();
			
			// 将 Pointer 转化为 java类
			HCNetSDK.NET_SDK_MANUAL_THERMOMETRY thermometry = new HCNetSDK.NET_SDK_MANUAL_THERMOMETRY();
//			thermometry.write();
			Pointer pthermometry = thermometry.getPointer();
			pthermometry.write(0, pBuffer.getByteArray(0, thermometry.size()), 0, thermometry.size());
			thermometry.read();
			ruleName = new String(thermometry.struRuleInfo.szRuleName).trim();
			if (thermometry.struRuleInfo.byRuleCalibType == 0) {// 点测温
				fMaxTemp = fMinTemp = fAvgTemp = thermometry.struRuleInfo.struPointTherm.fPointTemperature;// 温度
			} else if (thermometry.struRuleInfo.byRuleCalibType == 1) {// 框测温
				fMaxTemp = thermometry.struRuleInfo.struRegionTherm.fMaxTemperature;
				fMinTemp = thermometry.struRuleInfo.struRegionTherm.fMinTemperature;
				fAvgTemp = thermometry.struRuleInfo.struRegionTherm.fAverageTemperature;
//				float fDiffTemp = thermometry.struLinePolygonThermCfg.fTemperatureDiff;
			} else if (thermometry.struRuleInfo.byRuleCalibType == 2) {// 线测温
				 fMaxTemp = thermometry.struRuleInfo.struRegionTherm.fMaxTemperature;
				 fMinTemp = thermometry.struRuleInfo.struRegionTherm.fMinTemperature;
				 fAvgTemp = thermometry.struRuleInfo.struRegionTherm.fAverageTemperature;
			} else {
				return;
			}
			
			map.put("anaAlias", ruleName);
			map.put("max", fMaxTemp);
			map.put("min", fMinTemp);
			map.put("avg", fAvgTemp);
			
			System.out.println(map);
			
			break;
		default:
			break;
		}
	}

}
